package com.tehui.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.tehui.R;
import com.tehui.utils.ui.UiUtils;

import java.util.ArrayList;

import static com.tehui.app.MyApplication.IS_TAOKE;

/**
 * Created by jasmine on 2017/3/1.
 */

//轮播适配器
public class RollViewPagerAdapter extends StaticPagerAdapter {

    private       ArrayList<String> list;
    private final RequestOptions    options;

    public RollViewPagerAdapter(ArrayList<String> list) {
        this.list = list;
        if (IS_TAOKE) {
            options = new RequestOptions().centerCrop().placeholder(R.drawable.sd1);
        } else {
            options = new RequestOptions().centerCrop().placeholder(R.drawable.sds1);
        }
    }

    @Override
    public View getView(ViewGroup container, int position) {

        View view = View.inflate(UiUtils.getContext(), R.layout.roll_view_pager_layout, null);

        ImageView ivPic = (ImageView) view.findViewById(R.id.ivPic);

        Glide.with(UiUtils.getContext()).load(list.get(position)).apply(options).transition(new
                DrawableTransitionOptions().crossFade(300)).into(ivPic);
        return view;
    }

    @Override
    public int getCount() {
        return list.size();
    }
}
